package cn.byapps.attendance.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间类处理
 * 
 * @author Mr.chen
 *
 */
public class TimeUtils {
	/*
	 * 获取日期
	 */
	public String getDay(Date date, Integer day) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, +day);// +1今天的时间加一天
		date = calendar.getTime();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.format(date);
	}

	/*
	 * 返回时间分钟差
	 */
	public int getMin(Date fromDate, Date toDate) throws ParseException {
		SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
		String fromDates = simpleFormat.format(fromDate);
		String toDates = simpleFormat.format(toDate);
		long from = simpleFormat.parse(fromDates).getTime();
		long to = simpleFormat.parse(toDates).getTime();
		int minutes = (int) ((to - from) / (1000 * 60));
		return minutes;// 返回时间分钟差

	}

	/**
	 * 
	 * @param fromDate
	 *            系统时间
	 * @param toDate
	 *            数据库时间
	 * @return
	 * @throws ParseException
	 */
	public boolean getCompare(Date fromDate, Date toDate) throws ParseException {
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if (fromDate.after(sdf.parse(sf.format(fromDate) + " "+toDate))) {
			System.out.println("+++++++true");
			return true;
		} else {
			System.out.println("+++++++false");
			return false;
		}
	}
}
